package com.gable.report.controller;

import com.alibaba.fastjson.JSON;
import com.gable.report.common.util.HttpHelper;
import com.gable.report.common.util.ReturnResultUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 杨青桦
 * @Description:  医院总览聊天
 * @Date: 2018/3/28 12:57
 */
@Controller
@RequestMapping("charts/hospital/overview")
public class ChartsForHospitalOverviewChatController {


    @Value("${hospital_webSocket_url}")
    private String hospitalWebSocketUrl;

    /** 
     * @Author: 杨青桦
     * @Description: 查询群历史信息
     * @Date: 2018/3/28 13:13
     */
    @RequestMapping(value = "chat/queryGroupChatRecord",method = RequestMethod.POST, produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryGroupChatRecord(String groupId, //群id
                                     String clientId ,//客户端id
                                     String indexPage,//当前页码
                                     String totalSize){//总条数

        String result;
        try {
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("groupId", groupId);
            paramMap.put("clientId", clientId);
            paramMap.put("indexPage", indexPage);
            paramMap.put("totalSize", totalSize);
            result = HttpHelper.postRequestResponseBodyAsString(hospitalWebSocketUrl+"chat/queryGroupChatRecord",paramMap);
            if("".equals(result)){
                return new ReturnResultUtil(0,"网络异常");
            }
            return JSON.parseObject(result,ReturnResultUtil.class);
        } catch (Exception e){
            e.printStackTrace();
            return new ReturnResultUtil(0,"查询异常");
        }

    }

    /**
     * @Author: 杨青桦
     * @Description:  查询群组成员
     * @Date: 2018/3/28 14:27
     * @param groupId
     * @return
     */
    @RequestMapping(value = "chat/queryGroupMembers",method = RequestMethod.POST, produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryGroupMembers(String groupId,
    String start,String limit){ //群id
        String result;
        try {
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("groupId", groupId);
            paramMap.put("start", start);
            paramMap.put("limit", limit);
            result = HttpHelper.postRequestResponseBodyAsString(hospitalWebSocketUrl+"chat/queryGroupMembers",paramMap);
            if("".equals(result)){
                return new ReturnResultUtil(0,"网络异常");
            }
            return JSON.parseObject(result,ReturnResultUtil.class);
        } catch (Exception e){
            e.printStackTrace();
            return new ReturnResultUtil(0,"查询异常");
        }
    }
}
